package com.zhangyu.shadow.ec.main.personal.profile;

import android.content.DialogInterface;
import android.support.v7.app.AlertDialog;
import android.view.View;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.listener.SimpleClickListener;
import com.zhangyu.shadow.core.delegate.ShadowDelegate;
import com.zhangyu.shadow.ec.R;
import com.zhangyu.shadow.ec.main.personal.list.ListBean;

/**
 * @author zhangyu
 * @date 2018/1/4
 */

public class UserProfileItemClickListener extends SimpleClickListener {
    private final ShadowDelegate mDelegate;
    private String[] mGenders = new String[]{"男","女","保密"};

    private UserProfileItemClickListener(ShadowDelegate delegate) {
        mDelegate = delegate;
    }

    public static UserProfileItemClickListener create(ShadowDelegate delegate) {
        return new UserProfileItemClickListener(delegate);
    }

    @Override
    public void onItemClick(BaseQuickAdapter adapter, final View view, int position) {
        ListBean listBean = (ListBean) adapter.getItem(position);
        int id = listBean != null ? listBean.getId() : 0;
        switch (id){
            case 1:
                break;
            case 3:
                getGenderDialog(new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        final TextView textView = (TextView) view.findViewById(R.id.tv_value);
                        textView.setText(mGenders[which]);
                        dialog.cancel();
                    }
                });
                break;
            default:
                break;
        }
    }

    private void getGenderDialog(DialogInterface.OnClickListener listener){
        final AlertDialog.Builder builder = new AlertDialog.Builder(mDelegate.getContext());
        builder.setSingleChoiceItems(mGenders,0,listener);
        builder.show();
    }

    @Override
    public void onItemLongClick(BaseQuickAdapter adapter, View view, int position) {

    }

    @Override
    public void onItemChildClick(BaseQuickAdapter adapter, View view, int position) {

    }

    @Override
    public void onItemChildLongClick(BaseQuickAdapter adapter, View view, int position) {

    }
}
